package IO流.综合练习.登录注册;

import java.io.*;
import java.util.Scanner;

public class 第二题 {
    public static void main(String[] args) throws IOException {
        Scanner sc=new Scanner(System.in);
        //1.提示用户进行输入
        System.out.print("请输入你的用户名:");
        String inputusername = sc.nextLine();
        System.out.print("请输入你的密码:");
        String inputpassword = sc.nextLine();
        //2.读取文件中的数据
        BufferedReader br=new BufferedReader(new FileReader("F\\username.txt"));
        String[] split = br.readLine().split("&");
        br.close();
        //获取用户名
        String name = split[0].split("=")[1];
        //获取密码
        String password = split[1].split("=")[1];
        //获取输错次数
        String count = split[2].split("=")[1];
        if (count.equals("3")){
            System.out.println("连续输入错误次数超过三次");
        }else {
            if (name.equals(inputusername)&&password.equals(inputpassword)){
                System.out.println("登录成功!");
            }else {
                int i = Integer.parseInt(count);
                i++;
                System.out.println("登录失败!,你已错误"+i+"次,连续错误3将会锁定账号!");
                //重新写入文件中
                BufferedWriter bw=new BufferedWriter(new FileWriter("F\\username.txt"));
                bw.write(split[0]+"&"+split[1]+"&"+"count="+i);
                bw.close();
            }
        }
    }
}
